package com.gu.controller;

import com.gu.VO.ServerResponse;
import com.gu.entity.ApartmentDO;
import com.gu.entity.ApartmentinfoDO;
import com.gu.service.ApartmentInfoService;
import com.gu.service.ApartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ProjectName: apartment-management-center
 * @Package: com.gu.controller
 * @ClassName: ApartmentInfoController
 * @Author: gusongliao
 * @Description: 小区简介控制器
 * @createDate 2021/03/23 21:43
 */

@Controller
@RequestMapping("/apartmentInfo")
public class ApartmentInfoController {


    @Autowired
    private ApartmentInfoService apartmentInfoService;


    @PostMapping("/updateApartmentInfo")
    @ResponseBody
    public ServerResponse updateApartment(@RequestBody ApartmentinfoDO apartmentinfoDO){
        return apartmentInfoService.update(apartmentinfoDO);
    }

    @GetMapping("/getApartmentInfo")
    public String getApartment(HttpServletRequest request){
        ApartmentinfoDO apartmentinfoDO = apartmentInfoService.getById(1);
        request.getServletContext().setAttribute("apartmentInfo",apartmentinfoDO.getApartmentinfo());
        return "handleApartmentInfo";
    }


    @GetMapping("/apartmentInfoView")
    public String getApartmentInfo(HttpServletRequest request){
        ApartmentinfoDO apartmentinfoDO = apartmentInfoService.getById(1);
        request.getServletContext().setAttribute("apartmentInfo",apartmentinfoDO.getApartmentinfo());
        return "apartmentInfoView";
    }

    @PostMapping("/updatePassword")
    @ResponseBody
    public ServerResponse updatePassword(String password,String rePassword){
        return apartmentInfoService.updatePassword(password,rePassword);
    }

    @PostMapping("/loginSystem")
    @ResponseBody
    public ServerResponse loginSystem(String password){
        return apartmentInfoService.loginSystem(password);
    }









}



